package cbfg.common.webview;

import android.graphics.Bitmap;
import android.webkit.WebView;

public class ProgressWebHook extends WebHook {
    
    private final IWebViewLoading mWebViewLoading;

    public ProgressWebHook(IWebViewLoading loading) {
        this.mWebViewLoading = loading;
    }

    @Override
    public void onPageStarted(WebView webView, String url, Bitmap favicon) {
        super.onPageStarted(webView, url, favicon);
        startLoading();
    }

    @Override
    public void onPageFinished(WebView webView, String url) {
        super.onPageFinished(webView, url);
        stopLoading();
    }

    @Override
    public void onReceivedError(WebView webView, String url, int errorCode, String description) {
        super.onReceivedError(webView, url, errorCode, description);
        stopLoading();
    }

    @Override
    public void onProgressChanged(WebView webView, int newProgress) {
        super.onProgressChanged(webView, newProgress);
        mWebViewLoading.onProgress(getContext(), newProgress);
    }
}
